package kr.co.doriclassic.chapter24.student.service;
import java.util.Comparator;
import java.util.Scanner;

import kr.co.doriclassic.chapter24.student.dao.InterfaceDao;
import kr.co.doriclassic.chapter24.student.vo.Department;

public class DepartmentService extends ServiceItem<Department> {

	public DepartmentService(InterfaceDao<Department> dao, Scanner sc) {
		super(dao, sc);		
	}

	@Override
	public Department inputItemInfo(boolean gubun) {
	System.out.println("학과번호 학과명");
	Department dept = new Department(sc.nextInt(), sc.next().trim());
	if(gubun){
		System.out.println("위치");
		dept.setFloor(sc.nextInt());		
	}
	return dept;	
	}

	@Override
	public void prnSubMenu() {
		System.out.println("1. 이름 2. 위치 3. 번호 정렬");
		switch (sc.nextInt()) {
			case 1:
				dao.prnItemList(new Comparator<Department>() {
					@Override
					public int compare(Department o1, Department o2) {
						return o1.getDepName().hashCode()-o2.getDepName().hashCode();
					}
				});
				break;
			case 2:
				dao.prnItemList(new Comparator<Department>() {
					@Override
					public int compare(Department o1, Department o2) {
						return o1.getFloor()-o2.getFloor();
					}
				});
				break;
			default:
				dao.prnItemList(null);
				break;
		}	
	}
}
